#
#

TOP :=	    .
include	    $(TOP)/config/config.mk

NAME	    := cflaws
BINDIR	    := $(PREFIX)/bin
MAN1DIR	    := $(PREFIX)/man/man1

DIR = src

# -- CIL

CIL_VERSION := 1.3.2
CIL_TAR     := cil-$(CIL_VERSION).tar.gz
CIL_URL	    := http://manju.cs.berkeley.edu/cil/distrib/$(CIL_TAR)

# -- high-level targets
.PHONY: all clean install test 

all:	cil
	for d in $(DIR); do $(MAKE) -C $$d $@; done

clean:	
	for d in $(DIR); do $(MAKE) -C $$d $@; done
	rm -f test.* gmon.out
	rm -f VERSION

clobber: clean
	for d in $(DIR); do $(MAKE) -C $$d $@; done
	rm -r cil

install: src/$(NAME).$(BINEXT) doc/$(NAME).man $(BINDIR) $(MAN1DIR)
	cp src/$(NAME).$(BINEXT) $(BINDIR)/$(NAME) 
	cp doc/$(NAME).man $(MAN1DIR)/$(NAME).1

$(BINDIR):
	mkdir -p $@

$(MAN1DIR):
	mkdir -p $@

VERSION:
	svn -v list . | sort -rn | head -1 | awk '{print $$1}' > $@

$(TOP)/config/config.mk:    
	@echo "config/config.mk is missing. Have you run ./configure?"
	@exit 1

# -- CIL

$(CIL_TAR):
	curl -O $(CIL_URL)

cil:    $(CIL_TAR)
	rm -rf cil
	tar zxvf $(CIL_TAR)
	(cd cil && ./configure --prefix=$$PWD && make && make install) 
	ranlib cil/lib/cil/libperfcount.a       

